#pragma once

#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/threadpool.hpp>

using namespace boost::threadpool;

namespace hc
{
	typedef boost::mutex::scoped_lock TLock;
	typedef boost::mutex TMutex;
	typedef boost::condition TCondition;

	void HC_API sleep(int ms);

	class HC_API TEvent : noncopyable
	{
	public:
		//If autoReset is true, the event is automatically reset after a wait() successfully returns.
		TEvent(bool autoReset = true);
		~TEvent();
		void Set();
		void Reset();

		// Waits for the event to become signalled.
		void Wait();

		/// Waits for the event to become signalled. Returns true if the event became signalled within the specified time interval, false otherwise.
		bool Wait(long milliseconds);
			
	private:
		boost::mutex		m_mtx;
		boost::condition	m_cnd;
		bool				m_auto;
		volatile bool		m_state;

	};
}